const express = require("express");
const followModel = require("../../model/followModel");

const router = express.Router();

//接口5:关注
router.post("/addfollow", (req, res) => {
    let { user_id, follow_user, follow_name, follow_avators } = req.body;
    followModel
        .addFollow({ user_id, follow_user, follow_name, follow_avators })
        .then((data) => {
            res.send(data);
        })
        .catch((err) => {
            res.send(err);
        });
});

//接口6:取消关注
router.post("/removefollow", (req, res) => {
    let { user_id, follow_user } = req.body;
    followModel
        .removeFollow({ user_id, follow_user })
        .then((data) => {
            res.send(data);
        })
        .catch((err) => {
            res.send(err);
        });
});

//接口3:获取关注数量
router.get("/follwercount", (req, res) => {
    let { user_id } = req.query;
    followModel
        .getFollowCount({ user_id })
        .then((data) => {
            res.send({
                code: 200,
                msg: "获取用户关注的数量",
                data,
            });
        })
        .catch((err) => {
            res.send({
                code: -1,
                msg: "获取异常",
                err,
            });
        });
});

//接口4:获取粉丝数量
router.get("/fanscount", (req, res) => {
    let { follow_user } = req.query;
    followModel
        .getFansCount({ follow_user })
        .then((data) => {
            res.send({
                code: 200,
                msg: "获取用户粉丝的数量",
                data,
            });
        })
        .catch((err) => {
            res.send({
                code: -1,
                msg: "获取异常",
                err,
            });
        });
});

//接口5：获取用户关注列表
router.get("/getfollow", (req, res) => {
    let { user_id } = req.query;
    followModel
        .getFollowList({ user_id })
        .then((data) => {
            res.send({
                code: 200,
                msg: "获取关注列表成功",
                data,
            });
        })
        .catch((err) => {
            res.send({
                code: -1,
                msg: "获取关注列表失败",
                err,
            });
        });
});

//接口6：获取用户粉丝列表
router.get("/getfans", (req, res) => {
    let { follow_user } = req.query;
    // console.log(follow_user);
    followModel
        .getFansList({ follow_user })
        .then((data) => {
            res.send({
                code: 200,
                msg: "获取粉丝列表成功",
                data,
            });
        })
        .catch((err) => {
            res.send({
                code: -1,
                msg: "获取粉丝列表失败",
                err,
            });
        });
});

module.exports = router;
